<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="javascript" type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript">
<%-- 	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}
		}
	}

	if (!request)
		alert("Error initializing XMLHttpRequest!");

	function getCustomerInfo() {
		var username = document.getElementById("username").value;
		var pswd = document.getElementById("pswd").value;
		var url = "<%=path%>/RegisterLoginAction?username=" + escape(username)
				+ "&pswd=" + escape(pswd);
		request.open("GET", url, true);
		request.onreadystatechange = updatePage;
		request.send(null);
	}

	function updatePage() {
		if (request.readyState == 4)
		if(request.status==200)
			{
			 if(XMLHttpRequest.responseText != ""){
                 username.innerHTML = "<font color='red'>" + XMLHttpRequest.responseText + "</font>";
                 username.focus(); 
             }else{
                 username.innerHTML = "恭喜您，用户名可以使用。 ";
             }
         }else{
             alert("请求失败，错误码=" + XMLHttpRequest.status);
     }
			}
	 --%>
	 
	// $.ajax();
	$(document).ready(function() {
		$("#username").click(function(){
			$.ajax({
				type:"get",
				url:"/<%=path%>/RegisterLoginAction.jsp?username="+$("#username").val(),
				dataType:"json",
				success:function(data){
					if(data.success) {
						$("#nameSearch").hide();
					}
					else {
						$("#nameSearch").show();
					}
				}
			})
		});
	});
	
	function dosubmit1() {  
        var th = document.getElementById("form");  
        if (th.username.value == "") {  
            alert("用户名不能为空");  
            th.username.focus();  
            return;  
        }  
  
        if (th.pswd.value == "") {  
            alert("密码不能为空");  
            th.pswd.focus();  
            return;  
        }  
        
        th.action="<%=path%>/RegisterLoginAction";
		th.submit();
	}
</script>
</head>
<body>
	<form id="form" method="post">
		姓名: <input type="text" name="username" id="username"><label id="nameSearch" style="color: red;display:none;">用户名重复!</label> <br />
		密码: <input type="password" name="pswd" id="pswd"><label id="pswdSearch" style="color: red;display: none;">密码不正确!</label> <br /> <input type="button"
			value="submit" onclick="javascript:dosubmit1()">
	</form>
</body>
</html>
